{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>会员卡分类编辑</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <input type="hidden" name="id" value="{$list.id}" id="">
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="title" value="{$list.title}" lay-verify="required"
                    placeholder="请输入分类名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">logo图</label>
            <input type="hidden" lay-verify="logo" name="logo" id="logo2" value="{$list.logo}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="logoBtn2"><i
                            class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="SLogo2" src="{$list.logo}">
                        <p id="demoText2"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">背景图</label>
            <input type="hidden" lay-verify="img" name="img" id="logo3" value="{$list.img}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="logoBtn3"><i
                            class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="SLogo3" src="{$list.img}">
                        <p id="demoText2"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员卡等级</label>
            <div class="layui-input-4">
                <input type="number" maxlength="4" name="level" lay-verify="required" value="{$list.level}" placeholder="请输入会员卡等级"
                    class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">当前会员卡所在等级，等级不能重复，而且必须连续，数字越大等级越高</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-4">
                <input type="radio" name="status" value="0" title="正常" {if $list.status==0}checked{/if}>
                <input type="radio" name="status" value="1" title="下架" {if $list.status==1}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买价格</label>
            <div class="layui-input-4">
                <input type="number" maxlength="6" name="need_money" value="{$list.need_money}" lay-verify="required|number"
                    placeholder="请输入购买等级价格" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">用户直接购买会员卡等级的价格</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">升级消费</label>
            <div class="layui-input-4">
                <input type="number" maxlength="6" name="next_money" value="{$list.next_money}" lay-verify="required"
                    placeholder="请输入升级所需消费" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">用户升级会员卡所需消费金额</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">折扣</label>
            <div class="layui-input-4">
                <input type="number" maxlength="4" name="percent" value="{$list.percent}" lay-verify="required" placeholder="请输入升级所需消费"
                    class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">当前会员卡等级折扣率，七折填写7</div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">会员卡权益</label>
            <div class="layui-input-block">
                {volist name='list_category' id='vo'}
                <input type="checkbox" name="cate_id" title="{$vo.title}" lay-skin="primary" value="{$vo.id}" {if $vo.sel}checked{/if}>
                {/volist}


            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submit" lay-submit=""
                    lay-filter="sys">{:lang('submit')}</button>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
    layui.use(['form', 'layer', 'upload'], function () {
        var form = layui.form, layer = layui.layer, upload = layui.upload, $ = layui.jquery;
        form.verify({
            title: function (value) {
                if (value == '') {
                    return '请输入标题！';
                }
            },
            logo: function (value) {
                if (value == '') {
                    return '请上传权益图片！';
                }
            },
            img: function (value) {
                if (value == '') {
                    return '请上传权益图片！';
                }
            }
        });
        //普通图片上传    后台登录页背景图片
        var uploadInst2 = upload.render({
            elem: '#logoBtn2'
            , url: '{:url("UpFiles/upload")}',
            accept: 'images',
            acceptMime: 'image/*'
            , size: 0
            , multiple: true
            , number: 1
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#SLogo2').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                if (res.errorCode == 8888) {
                    $('#logo2').val(res.url);
                } else {
                    $('#SLogo2').attr('src', '');
                    layer.msg(res.msg, { time: 2000, icon: 2 });
                }
            }
        });
        var uploadInst2 = upload.render({
            elem: '#logoBtn3'
            , url: '{:url("UpFiles/upload")}',
            accept: 'images',
            acceptMime: 'image/*'
            , size: 0
            , multiple: true
            , number: 1
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#SLogo3').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                if (res.errorCode == 8888) {
                    $('#logo3').val(res.url);
                } else {
                    $('#SLogo3').attr('src', '');
                    layer.msg(res.msg, { time: 2000, icon: 2 });
                }
            }
        });
        //提交监听
        form.on('submit(sys)', function (data) {
            $("#submit").attr({ disabled: "disabled" });
            let arr = []
            $("input:checkbox[name='cate_id']:checked").each(function (i) {
                arr[i] = $(this).val();
            });
            data.field.cate_id = arr.toString()
            loading = layer.load(1, { shade: [0.1, '#fff'] });
            $.post("{:url('edit')}", data.field, function (res) {
                layer.close(loading);
                if (res.errorCode == 8888) {
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        location.href = '{:url("index")}';
                    });
                } else {
                    $("#submit").removeAttr("disabled");
                    layer.msg(res.msg, { icon: 2, time: 1000 });
                }
            });
        })
    })


</script>


</body>

</html>